package com.honglang.module.article.entity;


import java.util.Date;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import com.honglang.module.user.entity.User;

@Entity
@Table(name ="article")
public class Article {

	/**
	 * @uml.property  name="id"
	 */
	private Integer id;


	/** 
	 * @uml.property name="articleCategories"
	 * @uml.associationEnd inverse="article:com.honglang.entity.ArticleCategories"
	 */
	private ArticleCategories articleCategories;


	private Set<KeyWord> keyWordSet;
	
	/**
	 * @uml.property  name="Content"
	 */
	private String content;

	
	private String articlePreView;
	
	
	
	/**
	 * @uml.property  name="title"
	 */
	private String title;
	
	
	
	/** 
	 * @uml.property name="author"
	 * @uml.associationEnd aggregation="shared" inverse="article:com.honglang.entity.User"
	 */
	private User author;

	

	/**
	 * @uml.property  name="writeDate"
	 */
	private Date writeDate;

	
	/**
	 * @uml.property  name="Notes"
	 */
	private String notes;

	

	private String articleSource;
	
	/**
	 * Getter of the property <tt>Content</tt>
	 * @return  Returns the content.
	 * @uml.property  name="Content"
	 */
	@Column(length=20000)
	public String getContent() {
		return content;
	}

	/**
	 * Setter of the property <tt>Content</tt>
	 * @param Content  The content to set.
	 * @uml.property  name="Content"
	 */
	public void setContent(String content) {
		this.content = content;
	}

	/**
	 * Getter of the property <tt>title</tt>
	 * @return  Returns the title.
	 * @uml.property  name="title"
	 */
	@Column
	public String getTitle() {
		return title;
	}

	/**
	 * Setter of the property <tt>title</tt>
	 * @param title  The title to set.
	 * @uml.property  name="title"
	 */
	public void setTitle(String title) {
		this.title = title;
	}


	/** 
	 * Getter of the property <tt>author</tt>
	 * @return  Returns the author.
	 * @uml.property  name="author"
	 */
	@ManyToOne(fetch=FetchType.EAGER)
	@JoinColumn
	public User getAuthor() {
		return author;
	}

	/**
	 * Getter of the property <tt>writeDate</tt>
	 * @return  Returns the writeDate.
	 * @uml.property  name="writeDate"
	 */
	@Column
	public Date getWriteDate() {
		return writeDate;
	}

	/**
	 * Setter of the property <tt>writeDate</tt>
	 * @param writeDate  The writeDate to set.
	 * @uml.property  name="writeDate"
	 */
	public void setWriteDate(Date writeDate) {
		this.writeDate = writeDate;
	}

	/**
	 * Getter of the property <tt>Notes</tt>
	 * @return  Returns the notes.
	 * @uml.property  name="Notes"
	 */
	@Column
	public String getNotes() {
		return notes;
	}

	/**
	 * Setter of the property <tt>Notes</tt>
	 * @param Notes  The notes to set.
	 * @uml.property  name="Notes"
	 */
	public void setNotes(String notes) {
		this.notes = notes;
	}

	/** 
	 * Setter of the property <tt>author</tt>
	 * @param author  The author to set.
	 * @uml.property  name="author"
	 */
	public void setAuthor(User author) {
		this.author = author;
	}

	/** 
	 * Getter of the property <tt>articleCategories</tt>
	 * @return  Returns the articleCategories.
	 * @uml.property  name="articleCategories"
	 */
	@ManyToOne(fetch=FetchType.EAGER)
	@JoinColumn
	public ArticleCategories getArticleCategories() {
		return articleCategories;
	}

	/** 
	 * Setter of the property <tt>articleCategories</tt>
	 * @param articleCategories  The articleCategories to set.
	 * @uml.property  name="articleCategories"
	 */
	public void setArticleCategories(ArticleCategories articleCategories) {
		this.articleCategories = articleCategories;
	}

	/**
	 * Getter of the property <tt>id</tt>
	 * @return  Returns the id.
	 * @uml.property  name="id"
	 */
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Integer getId() {
		return id;
	}

	/**
	 * Setter of the property <tt>id</tt>
	 * @param id  The id to set.
	 * @uml.property  name="id"
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	@ManyToMany(fetch=FetchType.EAGER,cascade={CascadeType.PERSIST,CascadeType.MERGE})
	@JoinTable(
				name= "article_keyWords",
				joinColumns = {@JoinColumn(name ="article_id")},
				inverseJoinColumns = {@JoinColumn(name ="keyWord_id")}
			   )
	public Set<KeyWord> getKeyWordSet() {
		return keyWordSet;
	}

	public void setKeyWordSet(Set<KeyWord> keyWordSet) {
		this.keyWordSet = keyWordSet;
	}

	
	
	
	@Column
	public String getArticleSource() {
		return articleSource;
	}


	public void setArticleSource(String articleSource) {
		this.articleSource = articleSource;
	}
	
	
	
	@Column(length=10000)
	public String getArticlePreView() {
		return articlePreView;
	}

	public void setArticlePreView(String articlePreView) {
		this.articlePreView = articlePreView;
	}

	/**
	 * return the keyWordSet in String format ,split by ",";
	 * @return
	 */
	public String returnKeyWordString(){
		StringBuffer sb = new StringBuffer();
		if(null != this.keyWordSet && this.keyWordSet.size() > 0){
			for(KeyWord keyWord : this.keyWordSet){
				sb.append(keyWord.getName()+",");
			}
			return sb.deleteCharAt(sb.length()-1).toString();	
		}else{
			return null;
		}
		
	}
	
	
}
